package com.zz.ecommerce.searchManage.ent;

import com.zz.ecommerce.utils.SqlProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by fanshilei on 2015/12/11.
 */
@Repository
public interface EntRegDistDao {

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<TEntRegDist> queryEntRecords(@Param("tableName") final String tableName, @Param("qryObj") final TEntRegDist
        tEntRegDist, @Param("start") final int start,
                                      @Param("end") final int end, @Param("sortOrder") String order);

    @Select("SELECT TA.* FROM (SELECT T.*,ROWNUM RN FROM " +
            " (SELECT * FROM ${tableName} WHERE ORG_NO like '%${searchVal}%' OR ENT_CNAME like '%${searchVal}%' ORDER" +
            " BY ORG_NO DESC )" +
            " T WHERE ROWNUM<=${end}) TA WHERE TA.RN >=${start}")
    List<TEntRegDist> queryEntRecordsBySearch(@Param("tableName") final String tableName,
                                              @Param("searchVal") final String
                                                  searchVal, @Param("start") final int start,
                                              @Param("end") final int end, @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectCount")
    long getEntRecordsCnt(@Param("tableName") String tableName, @Param("qryObj") TEntRegDist tEntRegDist);

    @Select(
        "SELECT COUNT(1) FROM ${tableName} WHERE ORG_NO like '%||${searchVal}||%' OR ENT_CNAME like " +
        "'%||${searchVal}||%'")
    long getEntRecordsSearchCnt(@Param("tableName") String tableName, @Param("searchVal") String searchVal);
}
